<?php


namespace app\index\controller;

use think\Controller;
use think\Url;
use think\Request;

class Test extends Controller
{
    public function index($name = 'xk')
    {
        $temp = Url::build('/blog/archive/2015/05');
        $temp2 = url('/test', 'name=hahah');
        return $temp2;
    }

    public function getUrl()
    {
        $request = $this->request;
        $url = $request->url();
        echo 'url is:' . $url;
        echo '<br/>使用助手：' . request()->url();
    }

    public function getParam()
    {
        $request = request();
//        echo '111';
        echo 'name:' . $request->param('name', 'World', 'strtolower');
        echo '<br/>test:' . $request->param('test', 'thinkphp', 'strtoupper');
    }

    public function getParamforInput()
    {
        echo '请求参数为';
        dump(input());
    }

    public function getOther()
    {
        echo 'GET参数：';
        dump(input('get.'));
        echo 'GET参数：name';
        dump(input('get.name'));
        echo 'POST参数：name';
        dump(input('post.name'));
        echo 'cookie参数：name';
        dump(input('cookie.name'));
        echo '上传文件信息：image';
        dump(input('file.image'));
    }

    public function getTT()
    {
        $request = Request::instance();
        echo '请求方法：' . $request->method() . '<br/>';
        echo '资源类型：' . $request->type() . '<br/>';
        echo '访问IP：' . $request->ip() . '<br/>';
        echo '是否AJax请求：' . var_export($request->isAjax(), true) . '<br/>';
        echo '请求参数：';
        dump($request->param());
        echo '请求参数：仅包含name';
        dump($request->only(['name']));
        echo '请求参数：排除name';
        dump($request->except(['name']));
        echo '模块：' . $request->module();
        echo '<br/>控制器：' . $request->controller();
        echo '<br/>操作：' . $request->action();
    }

    public function testReponse()
    {
        $data = ['name' => 'thinkphp', 'status' => '1'];
        return jsonp($data, 200);
    }

    public function testRedirect($name)
    {
        if ($name == 'thinkphp')
            $this->success('欢迎使用ThinkPHP 5.0', 'hello');
        else if($name =='redirect')
        {
            $this->redirect('http://thinkphp.cn',301);
        }
        else return $this->error('错误的name', 'guest');
    }

    public function hello()
    {
        return 'Hello,ThinkPHP!';
    }

    public function guest()
    {
        return 'Hello,Guest!';
    }
}